﻿<link rel="stylesheet" type="text/css" href="/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="/easyui/demo.css">
<link rel="stylesheet" type="text/css" href="/easyui/base.css">
<link rel="stylesheet" type="text/css" href="/lib/Hui-iconfont/1.0.8/iconfont.css" />

<script type="text/javascript" src="/easyui/jquery.min.js"></script>
<script type="text/javascript" src="/easyui/jquery.easyui.min.js"></script>

<body class="easyui-layout">

<!-- 遮罩层 -->
<div id='PageLoadingTip' style="position: absolute; z-index: 1000; top: 0px; left: 0px; width: 100%; height: 100%; background: #222222; text-align: center;">
    <h1 style="top: 48%; position: relative"><img src="/media/image/loading.gif"></h1>
</div>

<div class="easyui-layout" style="width:100%;height:100%;padding-bottom:" id="conent-layout">

    <div data-options="region:'center',border:false" style="height: auto">
        <div class="easyui-layout" style="width:100%;height:100%;">
            <!-- 主表  -->
            <table id="constant_table" class="easyui-datagrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
                   data-options="rownumbers:true, pagination:true,singleSelect:true,url:'/constant-list/1/20',
                              method:'get',
                              toolbar:'#tb',
                              loadMsg : '数据加载中',
                              fitColumns : true,
                              onAfterEdit:function(index,row){
                                    var id        = row.id;
                                    var key       = row.constantKey;
                                    var keyDesc   = row.constantKeyDesc;
                                    var value     = row.constantValue;
                                    var valueDesc = row.constantValueDesc;
                                updateActions(id,key,keyDesc,value,valueDesc);
                             },
                             showFooter: true" >
                <thead>
                    <tr>
                        <th data-options="field:'constantKey', width:90,editor:{
                            type:'validatebox',
                            options:{
                                required:true,
                                missingMessage:'请输入常量索引名称'
                            }
                        }" >常量索引</th>
                        <th data-options="field:'constantKeyDesc', width:90,editor:{
                            type:'validatebox',
                            options:{
                                required:true,
                                missingMessage:'请输入常量索引描述名称'
                            }
                        }" >常量索引描述</th>
                        <th data-options="field:'constantValue', width:90,editor:{
                            type:'validatebox',
                            options:{
                                required:true,
                                missingMessage:'请输入常量索引名称'
                            }
                        }">常量值</th>
                        <th data-options="field:'constantValueDesc', width:90,editor:{
                            type:'validatebox',
                            options:{
                                required:true,
                                missingMessage:'请输入常量索引描述名称'
                            }
                        }">常量值描述</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</div>

<!-- 搜索框 -->
<div id="tb" style="padding:5px;height:auto">
	<div>
        事件描述:<input class="easyui-textbox" id="to" style="width:120px" >
        项目名称:
		<input class="easyui-combobox" name="language"id="key"
			   data-options="
				url : '/constants/SYSTEM',
				method: 'get',
				valueField:'value',
				textField:'text'
				">
		事件状态:
        <input class="easyui-combobox" name="language"id="key"
               data-options="
				url : '/constants/STATE',
				method: 'get',
				valueField:'value',
				textField:'text'
				">
		<a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchByParameter">搜索</a>
	</div>
    <div style="margin:5px 0;"></div>
    <div>
        <#list buttons as buttons>
            <a href="#" class="easyui-linkbutton" iconCls="${buttons.iconCls}" id="${buttons.buttonId}">${buttons.buttonName}</a>
        </#list>
    </div>
</div>

<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>

<!-- 按钮操作 -->
<script type="text/javascript">
    //新增
    $("#add").click(function () {
        var row = $('#constant_table').datagrid('getSelected');
        if (row){
            var index = $('#constant_table').datagrid('getRowIndex', row);
        } else {
            index = 0;
        }
        $('#constant_table').datagrid('insertRow', {
            index: index,
            row:{
                deleteFlag:'N'
            }
        });
        $('#constant_table').datagrid('selectRow',index);
        $('#constant_table').datagrid('beginEdit',index);
    })

    //保存
    $("#save").click(function () {
        var row = $('#constant_table').datagrid('getSelected');
        if (row){
            var index = $('#constant_table').datagrid('getRowIndex', row);
        } else {
            index = 0;
        }
        $('#constant_table').datagrid('endEdit',index);
    })

    //编辑
    $("#edit").click(function () {
        var row = $('#constant_table').datagrid('getSelected');
        if (row){
            var index = $('#constant_table').datagrid('getRowIndex', row);
            $('#constant_table').datagrid('selectRow',index);
            $('#constant_table').datagrid('beginEdit',index);
        } else {
            $.messager.show({
                title:'提示',
                msg:'请选择需要编辑的常量',
                timeout:3000,
                showType:'slide',
            });
        }

    })

    //删除
    $("#delete").click(function () {
        var row = $('#constant_table').datagrid('getSelected');
        if(!row){
            $.messager.show({
                title:'提示',
                msg:'请选择需要删除的常量',
                timeout:3000,
                showType:'slide',
            });
        }else{
            $.messager.confirm('删除信息','确定删除常量名称为:'+row.constantKeyDesc+"吗?",function(r){
                if (r){
                    var time = new Date();
                    $.ajax({
                        url :'/constant-ins-upd-del',
                        data : {id :row.id,flag:'Y'},
                        async : true,
                        success : function(){
                            $('#constant_table').datagrid('reload');
                        }
                    });
                }
            });
        }
    })
</script>

<!-- 增修操作 -->
<script type="text/javascript">
    function updateActions(id,key,keyDesc,value,valueDesc){
        var index = '';
        var tm = new Date();
        $.ajax({
            url : '/constant-ins-upd-del',
            data : {id:id,constantKey:key,constantKeyDesc:keyDesc,constantValue:value,constantValueDesc:valueDesc,tm:new Date()},
            async : true,
            type : 'post',
            beforeSend: function (request) {
                index = layer.load(1, {
                    shade: [0.5,'#ffffcc'] //0.1透明度的白色背景
                });
            },
            success :function () {
                layer.close(index);
                $('#constant_table').datagrid('reload');
            }
        })
    }
</script>


<!-- 分页 -->
<script type="text/javascript">
	$(function(){
		var p = $('#constant_table').datagrid().datagrid('getPager');
		p.pagination({
			pageSize: 20, //每页显示的记录条数，默认为10
			pageList: [20, 40, 60], //可以设置每页记录条数的列表
			onSelectPage: function (pageNumber, pageSize) {
			    if(pageNumber==0){
			        pageNumber = 1;
                }
				var handler = '/constant-list/'+pageNumber+"/"+pageSize;
				$('#constant_table').datagrid('options').url = handler;
				$('#constant_table').datagrid('reload');
			}
		});
	})
</script>

<script type="text/javascript">
    $(document).ready(function(){
        $('#conent-layout').layout('collapse','east');
    });
</script>

<!-- 遮罩层 -->
<script type="text/javascript">
    function _PageLoadingTip_Closes() {
        $("#PageLoadingTip").fadeOut("normal", function () {
            $(this).remove();
        });
    }
    var _pageloding_pc;
    $.parser.onComplete = function () {
        if (_pageloding_pc) clearTimeout(_pageloding_pc);
        _pageloding_pc = setTimeout(_PageLoadingTip_Closes, 1000);
    }
</script>